#include "window_common.h"

#if !defined(GKT_CONFIG_WINDOW_VOICE_MUTE_DISABLE) \
	|| !GKT_CONFIG_WINDOW_VOICE_MUTE_DISABLE

enum {
	WIDGET_ID_LIST = 0,
	WIDGET_ID_MAX
};

static const gkt_widget_list_item_s sc_window_voice_mute_list_items[] = {
GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_VOICE_COMBINED_ID(close), WINNDOW_SWITCH_ACTION_CLOSE),
	GKT_WIDGET_LIST_STATIC_ITEM(WINDOW_VOICE_COMBINED_ID(open), WINNDOW_SWITCH_ACTION_OPEN)
};
#define WINDOW_VOICE_MUTE_LIST_ITEM_NUMS	\
	sizeof(sc_window_voice_mute_list_items) / sizeof(gkt_widget_list_item_s)

static const gkt_widget_list_attr_s sc_window_voice_mute_list_attr = 
	GKT_WIDGET_LIST_STATIC_ATTR(WINDOW_VOICE_MUTE_LIST_ITEM_NUMS, 
		sc_window_voice_mute_list_items);

GKT_WINDOW_WIDGET_DESCS_DEFINE(voice_mute) = {
	[WIDGET_ID_LIST] = GKT_WIDGET_LIST_DESC(0, 
			&sc_window_voice_mute_list_attr),
};

typedef struct _window_voice_mute {
	uint32_t	select_value;
} window_voice_mute_s;
static window_voice_mute_s s_window_voice_mute;

static void window_voice_mute_complete(uint32_t state)
{
	uint32_t voice_flags = GKT_WINDOW_VOICE_F_NOTIFY_END | GKT_WINDOW_VOICE_F_NOTIFY_ERROR;
	gkt_window_voice_set_mute((int)state);

	gkt_window_voice_play(NULL, WINDOW_VOICE_COMBINED_ID(set_success), voice_flags, NULL);
}

static uint8_t voice_mute_play_over=0;
static int window_voice_mute_event_handler(
				uint32_t major_type, uint32_t minor_type, 
				uint32_t widget_id, uint32_t data)
{
	int retval = GKT_EVENT_HANDLE_CONTINUE;

	switch (major_type) {
		case GKT_EVENT_WINDOW:
			if (minor_type == GKT_WINDOW_INIT)
				s_window_voice_mute.select_value = gp_window_data->voice_mute_enable;
			else if (minor_type == GKT_WINDOW_ACTIVE)
				window_common_mask_except_number_repeat_return(WINDOW_VOICE_MUTE_LIST_ITEM_NUMS);
			else if (minor_type == GKT_WINDOW_UNINIT) {
				if ((s_window_voice_mute.select_value < WINNDOW_SWITCH_ACTION_MAX)
					&& ((int)s_window_voice_mute.select_value != gp_window_data->voice_mute_enable)) 
				{
					gp_window_data->voice_mute_enable = (int)s_window_voice_mute.select_value;
					window_data_save();
				}
			}

			retval = GKT_EVENT_HANDLE_COMPLETE;
			break;
		case GKT_EVENT_WIDGET:
			if(minor_type == GKT_WIDGET_EVENT_CLICK) {
				s_window_voice_mute.select_value = 
					sc_window_voice_mute_list_items[data].data;
				window_voice_mute_complete(s_window_voice_mute.select_value);
				voice_mute_play_over = 1;
				retval = GKT_EVENT_HANDLE_COMPLETE;
			}
			break;
		case GKT_EVENT_VOICE:
			if (voice_mute_play_over == 1) {
				voice_mute_play_over = 0;
				gkt_window_exit();
			}
			break;
		default:
			break;
	}

	return retval;
}
GKT_WINDOW_DESC_DEFINE(voice_mute);

#endif

